package cn.thoughtworks.school.programCenter.util.excel;

import org.apache.poi.hssf.usermodel.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public abstract class Excel {

    protected List<Map<String, String>> data;
    protected HSSFWorkbook workbook;
    private HSSFCellStyle defaultCellStyle;
    public abstract HSSFWorkbook fillData();

    protected HSSFCell createCell(HSSFRow row, int index, String content, HSSFCellStyle style) {
        HSSFCell cell = row.createCell(index);
        cell.setCellStyle(style);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(content);
        return cell;
    }


    protected HSSFCellStyle getDefaultCellStyle() {
        if (Objects.nonNull(this.defaultCellStyle)) {
            return defaultCellStyle;
        }
        defaultCellStyle = workbook.createCellStyle();
        defaultCellStyle.setWrapText(false);
        defaultCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        defaultCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        return defaultCellStyle;
    }

    protected HSSFRow createRow(HSSFSheet sheet, int index) {
        HSSFRow row = sheet.createRow(index);
        row.setHeight((short) (25 * 25));
        return row;
    }


}
